#include <buola/gui.h>

#include <buola/widgets/ccheckbox.h>
#include <buola/widgets/ctheme.h>

namespace buola { namespace gui {

CCheckBox::CCheckBox()
    :   mPressed(false)
{
    SetFocusMode(EFocusMode::TAB|EFocusMode::MOUSE);
    get_default_theme()->SetBackground(this);
}

CCheckBox::~CCheckBox()
{}

void CCheckBox::SetCaption(const std::wstring &pCaption)
{
    mCaption=pCaption;
    Refresh();
}

///////////////////// Event handling //////////////////////
void CCheckBox::OnExpose(const CExposeEvent &pE)
{
    get_default_theme()->DrawCheckBox(pE.mGC,this,CTheme::DRAW_NONE);
}

void CCheckBox::OnButtonDown(const CMouseEvent &pE)
{
    if(pE.mButton!=EMouseButton::LEFT) return;
    mPressed=true;
}

void CCheckBox::OnButtonUp(const CMouseEvent &pE)
{
    if(pE.mButton!=EMouseButton::LEFT) return;
    if(mPressed)
        Toggle();
    mPressed=false;
}

void CCheckBox::OnFocusIn(const CFocusEvent &pE)
{
}

void CCheckBox::OnFocusOut(const CFocusEvent &pE)
{
}

void CCheckBox::OnKeyDown(const CKeyEvent &pE)
{
}

void CCheckBox::OnStyleChanged(TStyle pOld)
{
    if((pOld^GetStyle())&STYLE_FAKE)
    {
        if(GetStyle(STYLE_FAKE))
        {
            SetInputMode(EInputMode::MOUSETRANSPARENT);
        }
        else
        {
            SetInputMode(EInputMode::NORMAL);
        }
    }
}

void CCheckBox::OnCWChecked()
{
    Refresh();
}

/*namespace gui*/ } /*namespace buola*/ }
